package org.example;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;

/**
 * 验证数据量计算
 */
public class TestDataVolumeVerification {
    
    public static void main(String[] args) {
        // 配置参数
        LocalDate startDate = LocalDate.of(2023, 7, 1);
        LocalDate currentDate = LocalDate.now();
        int baseOrders = 30000;
        int monthlyIncrease = 3000;
        
        // 贷款金额范围（平均5000）
        int minLoanAmount = 3000; // 3000元
        int maxLoanAmount = 7000; // 7000元
        int avgLoanAmount = (minLoanAmount + maxLoanAmount) / 2; // 5000元
        
        // Vintage配置
        double targetVintageOverdueRate = 0.40; // 40%逾期率
        double normalRepayRate = 0.60; // 60%正常还款
        
        // 计算总订单数
        LocalDate month = startDate;
        int totalOrders = 0;
        int monthCount = 0;
        
        System.out.println("=== 每月订单数计算 ===");
        while (!month.isAfter(currentDate)) {
            int monthsFromStart = (int) (month.toEpochDay() - startDate.toEpochDay()) / 30;
            int monthlyOrders = baseOrders + (monthsFromStart * monthlyIncrease);
            totalOrders += monthlyOrders;
            monthCount++;
            
            System.out.println("月份: " + month + ", 订单数: " + monthlyOrders);
            
            month = month.plusMonths(1);
        }
        
        // 计算总金额
        BigDecimal totalLoanAmount = BigDecimal.valueOf(totalOrders).multiply(BigDecimal.valueOf(avgLoanAmount));
        
        // 估算在途余额
        // 假设40%的订单逾期/未结清，平均剩余80%的金额
        BigDecimal overdueRate = new BigDecimal("0.40"); // 40%逾期/未结清
        BigDecimal remainingRate = new BigDecimal("0.80"); // 平均剩余80%的金额
        BigDecimal estimatedOutstanding = totalLoanAmount.multiply(overdueRate).multiply(remainingRate);
        
        System.out.println("\n=== 计算结果 ===");
        System.out.println("总月数: " + monthCount);
        System.out.println("总订单数: " + totalOrders);
        System.out.println("平均贷款金额: " + avgLoanAmount + " 元");
        System.out.println("总贷款金额: " + totalLoanAmount.divide(new BigDecimal("100000000"), 2, RoundingMode.HALF_UP) + " 亿");
        System.out.println("估算在途余额: " + estimatedOutstanding.divide(new BigDecimal("100000000"), 2, RoundingMode.HALF_UP) + " 亿");
        
        // 验证是否达到目标
        BigDecimal targetLoanAmount = new BigDecimal("5000000000"); // 50亿
        BigDecimal targetOutstandingAmount = new BigDecimal("2000000000"); // 20亿
        
        System.out.println("\n=== 目标验证 ===");
        System.out.println("目标总贷款金额: 50亿");
        System.out.println("实际总贷款金额: " + totalLoanAmount.divide(new BigDecimal("100000000"), 2, RoundingMode.HALF_UP) + " 亿");
        System.out.println("目标在途余额: 20亿");
        System.out.println("估算在途余额: " + estimatedOutstanding.divide(new BigDecimal("100000000"), 2, RoundingMode.HALF_UP) + " 亿");
        
        if (totalLoanAmount.compareTo(targetLoanAmount) >= 0) {
            System.out.println("✅ 总贷款金额达到目标");
        } else {
            System.out.println("❌ 总贷款金额未达到目标");
        }
        
        if (estimatedOutstanding.compareTo(targetOutstandingAmount) >= 0) {
            System.out.println("✅ 在途余额达到目标");
        } else {
            System.out.println("❌ 在途余额未达到目标");
        }
    }
}




